home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol06 / 02 / winmem32 / front.c < prev    next >
Text File  |  1991-02-28  |  6KB  |  224 lines

  1. /*******************************************************************
  2.     PROGRAM: Front.c
  3.  
  4.     PURPOSE: Front End for Mixed 16 and 32 bit program under Windows.
  5. ********************************************************************/
  6.  
  7. #include <windows.h>    /* required for all Windows applications */
  8. #include "front.h"      /* specific to this program */
  9.  
  10. HANDLE hInst;           /* current instance */
  11.  
  12. /*******************************************************************
  13.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  14.  
  15.     PURPOSE: calls initialization function, processes message loop
  16. ********************************************************************/
  17. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  18. HANDLE hInstance;
  19. HANDLE hPrevInstance;
  20. LPSTR lpCmdLine;
  21. int nCmdShow;
  22. {
  23. MSG msg;
  24.  
  25.     if (!hPrevInstance)
  26.     if (!InitApplication(hInstance))
  27.         return FALSE;
  28.  
  29.     if (!InitInstance(hInstance, nCmdShow))
  30.         return FALSE;
  31.  
  32.     while (GetMessage(&msg,NULL,NULL,NULL)) {
  33.  
  34.     TranslateMessage(&msg);
  35.     DispatchMessage(&msg);
  36.  
  37.     }
  38.     return msg.wParam;
  39. }
  40.  
  41. /********************************************************************
  42.     FUNCTION: InitApplication(HANDLE)
  43.  
  44.     PURPOSE: Initializes window data and registers window class
  45. ********************************************************************/
  46. BOOL InitApplication(HANDLE hInstance)  {
  47. WNDCLASS  wc;
  48.  
  49.     wc.style = NULL;
  50.     wc.lpfnWndProc = MainWndProc;
  51.  
  52.     wc.cbClsExtra = 0;
  53.     wc.cbWndExtra = 0;
  54.     wc.hInstance = hInstance;
  55.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  56.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  57.     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  58.     wc.lpszMenuName =  "FrontMenu";
  59.     wc.lpszClassName = "FrontWClass";
  60.  
  61.     /* Register the window class and return success/failure code. */
  62.  
  63.     return RegisterClass(&wc);
  64.  
  65. }
  66.  
  67. /********************************************************************
  68.     FUNCTION:  InitInstance(HANDLE, int)
  69.  
  70.     PURPOSE:  Saves instance handle and creates main window
  71. ********************************************************************/
  72. BOOL InitInstance(HANDLE hInstance,int nCmdShow)    {
  73. HWND    hWnd;
  74.  
  75.     hInst = hInstance;
  76.  
  77.     hWnd = CreateWindow(
  78.         "FrontWClass",
  79.         "Front Sample Application",
  80.         WS_OVERLAPPEDWINDOW,
  81.         CW_USEDEFAULT,
  82.         CW_USEDEFAULT,
  83.         CW_USEDEFAULT,
  84.         CW_USEDEFAULT,
  85.         NULL,
  86.         NULL,
  87.         hInstance,
  88.         NULL
  89.     );
  90.  
  91.     if (!hWnd)
  92.         return FALSE;
  93.  
  94.     ShowWindow(hWnd, nCmdShow);
  95.     UpdateWindow(hWnd);
  96.     return TRUE;
  97. }
  98.  
  99. /********************************************************************
  100.     FUNTION: DoAboutBox
  101.     PURPOSE: Put up the about box.
  102. ********************************************************************/
  103.  
  104. void    DoAboutBox(HWND hWnd)   {
  105. FARPROC lpProcAbout;
  106.  
  107.     lpProcAbout = MakeProcInstance(About, hInst);
  108.  
  109.     DialogBox(hInst,"AboutBox",hWnd,lpProcAbout);
  110.  
  111.     FreeProcInstance(lpProcAbout);
  112. }
  113.  
  114. /********************************************************************
  115.     FUNTION: Inform
  116.     PURPOSE: Inform the user of progress.
  117. ********************************************************************/
  118. void    Inform(HWND hWnd,LPSTR s)   {
  119.     MessageBox(hWnd,s,"Front",MB_OK);
  120. }
  121.  
  122. /********************************************************************
  123.     FUNTION: Notify
  124.     PURPOSE: Notify the user of a problem.
  125. ********************************************************************/
  126. void    Notify(HWND hWnd,LPSTR s)   {
  127.     MessageBox(hWnd,s,"Front",MB_OK | MB_ICONHAND);
  128. }
  129.  
  130. /********************************************************************
  131.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  132.     Processes the following
  133.     MESSAGES:
  134.  
  135.     WM_COMMAND    - application menu (About dialog box)
  136.     WM_DESTROY    - destroy window
  137. ********************************************************************/
  138. long FAR PASCAL MainWndProc(hWnd,message,wParam,lParam)
  139. HWND hWnd;        /* window handle           */
  140. unsigned message;     /* type of message             */
  141. WORD wParam;          /* additional information      */
  142. LONG lParam;          /* additional information      */
  143. {
  144.     switch (message) {
  145.  
  146.     case WM_COMMAND:
  147.         switch (wParam) {
  148.  
  149.             case    IDM_ABOUT:
  150.                 DoAboutBox(hWnd);
  151.             break;
  152.  
  153.         case    IDM_LOADENGINE:
  154.             Inform(hWnd,"Now Loading Engine");
  155.  
  156.             if (LoadEngine(hWnd,"back.exp"))
  157.                 Inform(hWnd,"Engine Intialized");
  158.             else
  159.                 Notify(hWnd,"Could Not Load Engine");
  160.  
  161.         break;
  162.  
  163.             case    IDM_CALLENGINE:
  164.             Inform(hWnd,"Now Calling Engine");
  165.  
  166.                 CallEngine(hWnd);
  167.  
  168.             Inform(hWnd,"Engine Has Returned");
  169.         break;
  170.  
  171.         case    IDM_KILLENGINE:
  172.             Inform(hWnd,"Now Purging Engine");
  173.  
  174.             KillEngine(hWnd);
  175.  
  176.             Inform(hWnd,"Engine Has Been Purged");
  177.  
  178.         default:
  179.             return DefWindowProc(hWnd,
  180.                          message,
  181.                                  wParam,
  182.                          lParam);
  183.         }
  184.  
  185.     break;
  186.  
  187.     case WM_DESTROY:
  188.         PostQuitMessage(0);
  189.     break;
  190.  
  191.     default:
  192.         return DefWindowProc(hWnd, message, wParam, lParam);
  193.     }
  194.     return NULL;
  195. }
  196.  
  197. /********************************************************************
  198.     FUNCTION: About(HWND, unsigned, WORD, LONG)
  199.  
  200.     PURPOSE:  Processes messages for "About" dialog box
  201. ********************************************************************/
  202. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  203. HWND hDlg;
  204. unsigned message;
  205. WORD wParam;
  206. LONG lParam;
  207. {
  208.     switch (message) {
  209.     case WM_INITDIALOG:
  210.         return TRUE;
  211.  
  212.     case WM_COMMAND:
  213.         if (wParam == IDOK || wParam == IDCANCEL) {
  214.  
  215.         EndDialog(hDlg, TRUE);
  216.         return TRUE;
  217.         }
  218.  
  219.     break;
  220.     }
  221.  
  222.     return FALSE;
  223. }
  224.